<?php
set_time_limit(0);
include "pdo.php";
$str=curl('https://www.readnovel.com/free/all?pageNum=1&pageSize=10&gender=1&catId=20001&isFinish=-1&isVip=1&size=-1&updT=-1&orderBy=0');
$preg='#right-book-list.*page-box.*cf#isU';
preg_match($preg,$str,$arr);
//print_r($arr);die;
$preg_content='#<li>.*<div class=".*">.*<a href="(.*)" .*>(.*)</a>.*</div>.*<div class=".*">.*<h3>.*</h3>.*<h4>.*<a class=".*">(.*)</a>.*</h4>.*<p class=".*">.*<span class=".*">(.*)</span>.*<span class=".*">.*</span>.*<span class=".*">.*</span>.*</p>.*<p class=".*">(.*)</p>.*</div>.*</li>#isU';
preg_match_all($preg_content,$arr[0],$arr_content);
print_r($arr_content);die;
$pdo=new pdo1();
//入库
foreach($arr_content[1] as $k=>$v)
{
    $arr1['url']=$arr_content[1][$k];
    $arr1['imgurl']='https:'.$arr_content[2][$k];
    $arr1['author']=$arr_content[3][$k];
    $arr1['type']=$arr_content[4][$k];
    $arr1['message']=trim($arr_content[5][$k]);
    $pdo->insert($arr1,'zjmain');
}
    //$mulu_url="https://www.readnovel.com/book/21988277000642502";
////echo $mulu_url;
////采集章节。。。。。。。。。。。。。。。。。。。
//    $menlu=curl($mulu_url);
////echo $menlu;die;
//    $menlu_preg='#作品信息.*作品互动区#isU';
//    preg_match($menlu_preg,$menlu,$arr_content);
//    $mulu_info='#<li data-rid=".*"><a href="(.*)" target=".*" data-cid=".*" title=".*">(.*)</a>.*</li>#isU';
//    preg_match_all($mulu_info,$arr_content[0],$mulu_arr_info);
////print_r($mulu_arr_info);die;
//    foreach($mulu_arr_info[1]  as $key=>$value)
//    {
//        $arr_zj['zhangjie']=$mulu_arr_info[2][$key];
//        $arr_zj['url']=$mulu_arr_info[1][$key];
//        $arr_zj['title_id']=$id;
//        $content_url='https:'.$value;
//        $content_arr=curl($content_url);
//        $preg_content='#top-head box-center cf.*chapter-control dib-wrap#isU';
//        preg_match($preg_content,$content_arr);
//
//        //内容
//        $arr_zj['content']=$content_arr[0];
//        $pdo->insert($arr_zj,'zj');
//    }

//


//print_r($arr_content);die;
//第二大块。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
//获得该书的地址

//print_r($mulu_arr_info);die;


//获得小说章节相对应的具体内容
//$content="https://www.readnovel.com/chapter/21988277000642502/7506385478684836";
//$content_arr=curl($content);
//$preg_content='#top-head box-center cf.*chapter-control dib-wrap#isU';
//preg_match($preg_content,$content_arr,$arr);
////print_r($arr);die;
//print_r($content_arr);die;

function curl($url)
{
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    $str=curl_exec($ch);
    curl_close($ch);
    return $str;

}
